/**
 * 
 */
package cn.maszy.service.impl.financialManagement;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.dao.financialManagement.B_T_Ufp_FinancialMapper;
import cn.maszy.model.financialManagement.B_T_Ufp_Financial;
import cn.maszy.model.financialManagement.B_T_Ufp_FinancialExample;
import cn.maszy.model.financialManagement.B_T_Ufp_FinancialExample.Criteria;
import cn.maszy.service.financialManagement.B_T_Ufp_FinancialService;


@Service
public class B_T_Ufp_FinancialServiceImpl implements B_T_Ufp_FinancialService{
	@Autowired
	private B_T_Ufp_FinancialMapper b_T_Ufp_FinancialMapper;
	
	
	public int update(B_T_Ufp_Financial b_T_Ufp_Financial,String flag) {
			 if(b_T_Ufp_Financial.getUuid()==null||"".equals(b_T_Ufp_Financial.getUuid())){
				 b_T_Ufp_Financial.setUuid(UUID.randomUUID().toString());
				 if(flag.equals("zc")){
				 b_T_Ufp_Financial.setState("0");
				 }	
				 if(flag.equals("sr")){
					 b_T_Ufp_Financial.setState("1");
				 }
				 b_T_Ufp_Financial.setOperator(SessionFactory.getSessionUserRealNam());
				 b_T_Ufp_Financial.setIsDelete(0);
				 b_T_Ufp_Financial.setCreateTime(new Date());
				 b_T_Ufp_Financial.setCreateUser(SessionFactory.getSessionUserRealNam());
				 return b_T_Ufp_FinancialMapper.insert(b_T_Ufp_Financial);
			 }else{
				 b_T_Ufp_Financial.setUpdateTime(new Date());
				 b_T_Ufp_Financial.setUpdateUser(SessionFactory.getSessionUserRealNam());
				 return b_T_Ufp_FinancialMapper.updateByPrimaryKeySelective(b_T_Ufp_Financial);
			 }
		
			
	
		
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_FinancialService#selectOne(java.lang.String)
	 */
	public B_T_Ufp_Financial selectOne(String adminid) {
		// TODO Auto-generated method stub
		B_T_Ufp_Financial record=b_T_Ufp_FinancialMapper.selectByPrimaryKey(adminid);
		return record;
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_FinancialService#delete(java.lang.String)
	 */
	public int delete(String checkIds) {
		// TODO Auto-generated method stub
		for (String id : checkIds.split(", ")) {
			b_T_Ufp_FinancialMapper.deleteByPrimaryKey(id);
		}
		return 1;
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_FinancialService#count(cn.maszy.model.investment.B_T_Ufp_FinancialExample)
	 */
	public int count(B_T_Ufp_FinancialExample example,B_T_Ufp_FinancialMapper b_T_Ufp_FinancialMapper) {
		// TODO Auto-generated method stub
		return b_T_Ufp_FinancialMapper.countByExample(example);
	}

	/* (non-Javadoc)
	 * @see cn.maszy.service.investment.B_T_Ufp_FinancialService#selectList(cn.maszy.model.investment.B_T_Ufp_Financial)
	 */
	public Pager<B_T_Ufp_Financial> selectList(B_T_Ufp_Financial b_T_Ufp_Financial,Pager<B_T_Ufp_Financial> pager,String flag,String strattime,String endtime) {
		// TODO Auto-generated method stub
		// 添加查询条件
		B_T_Ufp_FinancialExample example=new B_T_Ufp_FinancialExample();
		Criteria criteria = example.createCriteria();
		if(flag.equals("zc")){
			criteria.andStateLike("0");
		}
		if(flag.equals("sr")){
			criteria.andStateLike("1");
		}
		if(strattime!=null&&!"".equals(strattime)){
			criteria.andDateGreaterThanOrEqualTo(strattime);
			}
		if(endtime!=null&&!"".equals(endtime)){
			criteria.andDateLessThanOrEqualTo(endtime);
			}
		if(b_T_Ufp_Financial!=null){
			if(b_T_Ufp_Financial.getInternally()!=null&&!"".equals(b_T_Ufp_Financial.getInternally())){
				criteria.andInternallyLike("%"+b_T_Ufp_Financial.getInternally()+"%");
			}
		}else{
			criteria.andUuidIsNotNull();
		}
		example.or(criteria);
		int totalCount=new B_T_Ufp_FinancialServiceImpl().count(example,b_T_Ufp_FinancialMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
		
		// 取得总的记录条数
		List<B_T_Ufp_Financial>  list=b_T_Ufp_FinancialMapper.selectByExample(example);
		pager.setPageRecords(list);
		return pager;
	}

	public Pager<B_T_Ufp_Financial> selectList1(B_T_Ufp_Financial b_T_Ufp_Financial, Pager<B_T_Ufp_Financial> pager,String strattime,String endtime,List<B_T_Ufp_Financial> list_B_T_Ufp_Financial) {
		B_T_Ufp_FinancialExample example=new B_T_Ufp_FinancialExample();
		Criteria criteria = example.createCriteria(); 
		if(strattime!=null&&!"".equals(strattime)){
			criteria.andDateGreaterThanOrEqualTo(strattime);
			}
		if(endtime!=null&&!"".equals(endtime)){
			criteria.andDateLessThanOrEqualTo(endtime);
			}
		if(b_T_Ufp_Financial!=null){
			if(b_T_Ufp_Financial.getInternally()!=null&&!"".equals(b_T_Ufp_Financial.getInternally())){
				criteria.andInternallyLike("%"+b_T_Ufp_Financial.getInternally()+"%");
			}
		}else{
			criteria.andUuidIsNotNull();
		}
		example.or(criteria);
		int totalCount=new B_T_Ufp_FinancialServiceImpl().count(example,b_T_Ufp_FinancialMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
		
		// 取得总的记录条数
		List<B_T_Ufp_Financial>  list=b_T_Ufp_FinancialMapper.selectByExample(example);
		pager.setPageRecords(list);
		return pager;
		
	}
	

}
